/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package classcreator;

import java.util.Vector;

/**
 *
 * @author Stefano
 */
public class Constructor extends Method{
    public Constructor(String name){
        super(new MethodHeader(Naming.constructorType, name));
    }
    public Constructor(String name, Vector<Field> fields){
        super(new MethodHeader(Naming.constructorType, name));
        for(Field f:fields){
            if(f.isInitialized()) continue;
            if(!f.built) continue;
            header.addParameter(new Parameter(f.type,Naming.parameterGenerationName+f.name));
            super.addBodyLine("this."+f.name+" = "+Naming.parameterGenerationName+f.name+";");
        }
    }
    public Constructor(String name, Vector<Field> fields, Vector<Field> inherited){
        super(new MethodHeader(Naming.constructorType, name));
        if(inherited.size()>0){
            String inheritedList="";
            for(Field f:inherited){
                if(f.isInitialized()) continue;
                if(!f.built) continue;
                header.addParameter(new Parameter(f.type,Naming.parameterGenerationName+f.name));
                inheritedList=inheritedList+Naming.parameterGenerationName+f.name+", ";
            }
            inheritedList=inheritedList.substring(0, inheritedList.length()-2);
            super.addBodyLine("super("+inheritedList+");");
        }
        for(Field f:fields){
            if(f.isInitialized()) continue;
            if(!f.built) continue;
            header.addParameter(new Parameter(f.type,Naming.parameterGenerationName+f.name));
            super.addBodyLine("this."+f.name+" = "+Naming.parameterGenerationName+f.name+";");
        }
    }
}
